package I;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 菜单界面
 */
public class MenuPanel extends JPanel implements ActionListener {
    private ATMFrame atmFrame;
    private JLabel blanceLabel = new JLabel();
    private ImageIcon saveImg = new ImageIcon("picture/buttonSave.jpg");
    private ImageIcon findImg = new ImageIcon("picture/buttonFind.jpg");
    private ImageIcon getImg = new ImageIcon("picture/buttonGet.jpg");
    private ImageIcon modifyImg = new ImageIcon("picture/buttonModify.jpg");
    private ImageIcon offImg = new ImageIcon("picture/buttonOff.jpg");
    private JButton saveBtn = new JButton(saveImg);
    private JButton findBtn = new JButton(findImg);
    private JButton getBtn = new JButton(getImg);
    private JButton modifyBtn = new JButton(modifyImg);
    private JButton transferBtn = new JButton("转账");
    private JButton offBtn = new JButton(offImg);
    private Font font = new Font("微软雅黑",Font.BOLD,25);
    public MenuPanel(ATMFrame atmFrame){
        this.atmFrame = atmFrame;
        this.setLayout(null);
        saveBtn.setBounds(0,150,140,50);
        saveBtn.addActionListener(this);
        findBtn.setBounds(0,350,140,50);
        findBtn.addActionListener(this);
        getBtn.setBounds(0,550,140,50);
        getBtn.addActionListener(this);
        modifyBtn.setBounds(884,150,140,50);
        modifyBtn.addActionListener(this);
        transferBtn.setBounds(884,350,140,50);
        transferBtn.setFont(font);
        transferBtn.addActionListener(this);
        offBtn.setBounds(884,550,140,50);
        offBtn.addActionListener(this);
        this.add(saveBtn);
        this.add(findBtn);
        this.add(getBtn);
        this.add(modifyBtn);
        this.add(transferBtn);
        this.add(offBtn);

        this.setOpaque(false);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource()==saveBtn){

            atmFrame.switchPanel("save");
        }else if (e.getSource()==findBtn){
            atmFrame.getSearchPanel().showBlance();
            atmFrame.switchPanel("search");
        }else if (e.getSource()==getBtn){
            atmFrame.switchPanel("get");
        }else if (e.getSource()==modifyBtn){
            atmFrame.switchPanel("changePwd");
        }else if (e.getSource()==transferBtn){
            atmFrame.switchPanel("transfer");
        }else if (e.getSource()==offBtn){
            atmFrame.switchPanel("");
        }
    }
}
